//
//  WEXTabBarController.swift
//  microBlog
//
//  Created by apple on 16/4/16.
//  Copyright © 2016年 Hill. All rights reserved.
//

import UIKit

class WEXTabBarController: UITabBarController {
    
    // MARK: - 设置界面
    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = WEXTabBar()
        
        self.setValue(tabBar, forKey: "tabBar")
        
        let didClickButtonNewContent = {[weak self] in
            
//            print(".......")
            let composeView = WEXComposeView()
            
            composeView.show(self)
            
        }
        
        tabBar.didClickButtonNewContent = didClickButtonNewContent
        
        
        // 添加子控制器
        addChildViewController(WEXHomeTableViewController(), title: "首页", imgName: "tabbar_home")
        
        addChildViewController(WEXMessageTableViewController(), title: "消息", imgName: "tabbar_message_center")
        
        addChildViewController(WEXDiscoveryTableViewController(), title: "发现", imgName: "tabbar_discover")
        
        addChildViewController(WEXProfileTableViewController(), title: "我", imgName: "tabbar_profile")
        
        
    }

    // MARK: - 设置添加的子控件
     func addChildViewController(viewController: UIViewController, title: String,imgName: String ) {
        
        viewController.title = title
        viewController.tabBarItem.image = UIImage(named: imgName)
        viewController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        viewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()] , forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: viewController))
        
        
        
    }

}
